home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / misc / o-z / x-windows / mesa-amiwin / src / points.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  10.4 KB  |  437 lines

  1. /* points.c */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Id: points.c,v 1.20 1995/10/17 21:41:56 brianp Exp $
  26.  
  27. $Log: points.c,v $
  28.  * Revision 1.20  1995/10/17  21:41:56  brianp
  29.  * removed simple_ci/rgba_points() functions because of new device driver
  30.  *
  31.  * Revision 1.19  1995/09/28  19:39:10  brianp
  32.  * replaced ClipFlag[] with Unclipped[]
  33.  *
  34.  * Revision 1.18  1995/09/20  18:20:39  brianp
  35.  * prototype device driver changes described
  36.  *
  37.  * Revision 1.17  1995/09/13  14:50:38  brianp
  38.  * render an array of points rather than single points
  39.  *
  40.  * Revision 1.16  1995/07/25  18:36:32  brianp
  41.  * convert window coords from floats to ints by rounding, not truncating
  42.  *
  43.  * Revision 1.15  1995/07/15  14:03:58  brianp
  44.  * added texture mapped points
  45.  *
  46.  * Revision 1.14  1995/06/20  16:20:50  brianp
  47.  * do float-to-int depth scaling here instead of in draw.c
  48.  *
  49.  * Revision 1.13  1995/06/05  20:27:26  brianp
  50.  * better clipping of points with size > 1
  51.  *
  52.  * Revision 1.12  1995/05/22  21:02:41  brianp
  53.  * Release 1.2
  54.  *
  55.  * Revision 1.11  1995/05/12  16:57:22  brianp
  56.  * replaced CC.Mode!=0 with INSIDE_BEGIN_END
  57.  *
  58.  * Revision 1.10  1995/04/18  15:48:23  brianp
  59.  * fixed assignment of NULL to function pointers to prevent warnings on Suns
  60.  *
  61.  * Revision 1.9  1995/04/12  15:36:15  brianp
  62.  * updated to use DD.draw_* function pointers
  63.  *
  64.  * Revision 1.8  1995/03/24  15:33:32  brianp
  65.  * introduced VB
  66.  *
  67.  * Revision 1.7  1995/03/07  14:20:55  brianp
  68.  * updated for new XSetForeground/GC scheme
  69.  *
  70.  * Revision 1.6  1995/03/04  19:29:44  brianp
  71.  * 1.1 beta revision
  72.  *
  73.  * Revision 1.5  1995/03/04  19:16:47  brianp
  74.  * added size clamp
  75.  *
  76.  * Revision 1.4  1995/03/02  19:18:34  brianp
  77.  * new RasterMask logic
  78.  *
  79.  * Revision 1.3  1995/02/27  22:48:59  brianp
  80.  * modified for PB
  81.  *
  82.  * Revision 1.2  1995/02/27  15:08:12  brianp
  83.  * added Vcolor/Vindex scheme
  84.  *
  85.  * Revision 1.1  1995/02/24  14:26:49  brianp
  86.  * Initial revision
  87.  *
  88.  */
  89.  
  90.  
  91. #include "context.h"
  92. #include "dd.h"
  93. #include "feedback.h"
  94. #include "list.h"
  95. #include "macros.h"
  96. #include "pb.h"
  97. #include "span.h"
  98. #include "vb.h"
  99.  
  100.  
  101.  
  102.  
  103. void glPointSize( GLfloat size )
  104. {
  105.    if (CC.CompileFlag) {
  106.       gl_save_pointsize( size );
  107.    }
  108.    if (CC.ExecuteFlag) {
  109.       if (size<=0.0) {
  110.      gl_error( GL_INVALID_VALUE, "glPointSize" );
  111.      return;
  112.       }
  113.       if (INSIDE_BEGIN_END) {
  114.      gl_error( GL_INVALID_OPERATION, "glPointSize" );
  115.      return;
  116.       }
  117.  
  118.       CC.Point.Size = size;
  119.       CC.NewState = GL_TRUE;
  120.    }
  121. }
  122.  
  123.  
  124.  
  125. /**********************************************************************/
  126. /*****                    Rasterization                           *****/
  127. /**********************************************************************/
  128.  
  129.  
  130. /*
  131.  * There are 3 pairs (RGBA, CI) of point rendering functions:
  132.  *   1. simple:  size=1 and no special rasterization functions (fastest)
  133.  *   2. size1:  size=1 and any rasterization functions
  134.  *   3. general:  any size and rasterization functions (slowest)
  135.  *
  136.  * All point rendering functions take the same two arguments: first and
  137.  * last which specify that the points specified by VB[first] through
  138.  * VB[last] are to be rendered.
  139.  */
  140.  
  141.  
  142.  
  143. /*
  144.  * Put points in feedback buffer.
  145.  */
  146. static void feedback_points( GLuint first, GLuint last )
  147. {
  148.    GLuint i;
  149.  
  150.    for (i=first;i<=last;i++) {
  151.       if (VB.Unclipped[i]) {
  152.          GLfloat x, y, z, w;
  153.  
  154.          x = VB.Win[i][0];
  155.          y = VB.Win[i][1];
  156.          z = VB.Win[i][2];
  157.          w = VB.Clip[i][3];
  158.  
  159.          APPEND_TOKEN( (GLfloat) GL_POINT_TOKEN );
  160.          gl_feedback_vertex( x, y, z, w,
  161.                              VB.Color[i], VB.Index[i], VB.TexCoord[i] );
  162.       }
  163.    }
  164. }
  165.  
  166.  
  167.  
  168. /*
  169.  * Put points in selection buffer.
  170.  */
  171. static void select_points( GLuint first, GLuint last )
  172. {
  173.    GLuint i;
  174.  
  175.    for (i=first;i<=last;i++) {
  176.       if (VB.Unclipped[i]) {
  177.          GLfloat z = VB.Win[i][2];
  178.  
  179.          CC.HitFlag = GL_TRUE;
  180.          if (z < CC.HitMinZ) {
  181.             CC.HitMinZ = z;
  182.          }
  183.          if (z < CC.HitMinZ) {
  184.             CC.HitMaxZ = z;
  185.          }
  186.       }
  187.    }
  188. }
  189.  
  190.  
  191. /*
  192.  * CI points with size == 1.0
  193.  */
  194. static void size1_ci_points( GLuint first, GLuint last )
  195. {
  196.    GLuint i;
  197.  
  198.    for (i=first;i<=last;i++) {
  199.       if (VB.Unclipped[i]) {
  200.          GLint x, y, z;
  201.          x = (GLint) (VB.Win[i][0] + 0.5F);
  202.          y = (GLint) (VB.Win[i][1] + 0.5F);
  203.          z = (GLint) (VB.Win[i][2] * DEPTH_SCALE);
  204.          PB_WRITE_CI_PIXEL( x, y, z, (GLuint) VB.Index[i] );
  205.       }
  206.    }
  207.    PB_CHECK_FLUSH
  208. }
  209.  
  210.  
  211. /*
  212.  * RGBA points with size == 1.0
  213.  */
  214. static void size1_rgba_points( GLuint first, GLuint last )
  215. {
  216.    GLuint i;
  217.  
  218.    for (i=first;i<=last;i++) {
  219.       if (VB.Unclipped[i]) {
  220.          GLint x, y, z;
  221.          GLint red, green, blue, alpha;
  222.  
  223.          x = (GLint) (VB.Win[i][0] + 0.5F);
  224.          y = (GLint) (VB.Win[i][1] + 0.5F);
  225.          z = (GLint) (VB.Win[i][2] * DEPTH_SCALE);
  226.  
  227.          red   = (GLint) (VB.Color[i][0] * CC.RedScale);
  228.          green = (GLint) (VB.Color[i][1] * CC.GreenScale);
  229.          blue  = (GLint) (VB.Color[i][2] * CC.BlueScale);
  230.          alpha = (GLint) (VB.Color[i][3] * CC.AlphaScale);
  231.  
  232.          PB_WRITE_RGBA_PIXEL( x, y, z, red, green, blue, alpha );
  233.       }
  234.    }
  235.    PB_CHECK_FLUSH
  236. }
  237.  
  238.  
  239.  
  240. /*
  241.  * General CI points.
  242.  */
  243. static void general_ci_points( GLuint first, GLuint last )
  244. {
  245.    GLuint i;
  246.    GLint isize;
  247.  
  248.    isize = (GLint) (CLAMP(CC.Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE) + 0.5F);
  249.  
  250.    for (i=first;i<=last;i++) {
  251.       if (VB.Unclipped[i]) {
  252.          GLint x, y, z;
  253.          GLint x0, x1, y0, y1;
  254.          GLint ix, iy;
  255.  
  256.          x = (GLint) (VB.Win[i][0] + 0.5F);
  257.          y = (GLint) (VB.Win[i][1] + 0.5F);
  258.          z = (GLint) (VB.Win[i][2] * DEPTH_SCALE);
  259.  
  260.          if (isize&1) {
  261.             /* odd size */
  262.             x0 = x - isize/2;
  263.             x1 = x + isize/2;
  264.             y0 = y - isize/2;
  265.             y1 = y + isize/2;
  266.          }
  267.          else {
  268.             /* even size */
  269.             x0 = (GLint) (x + 0.5F) - isize/2;
  270.             x1 = x0 + isize-1;
  271.             y0 = (GLint) (y + 0.5F) - isize/2;
  272.             y1 = y0 + isize-1;
  273.          }
  274.  
  275.          PB_SET_INDEX( (GLuint) VB.Index[i] );
  276.  
  277.          for (iy=y0;iy<=y1;iy++) {
  278.             for (ix=x0;ix<=x1;ix++) {
  279.                PB_WRITE_PIXEL( ix, iy, z );
  280.             }
  281.          }
  282.          PB_CHECK_FLUSH
  283.       }
  284.    }
  285. }
  286.  
  287.  
  288. /*
  289.  * General RGBA points.
  290.  */
  291. static void general_rgba_points( GLuint first, GLuint last )
  292. {
  293.    GLuint i;
  294.    GLint isize;
  295.  
  296.    isize = (GLint) (CLAMP(CC.Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE) + 0.5F);
  297.  
  298.    for (i=first;i<=last;i++) {
  299.       if (VB.Unclipped[i]) {
  300.          GLint x, y, z;
  301.          GLint x0, x1, y0, y1;
  302.          GLint ix, iy;
  303.  
  304.          x = (GLint) (VB.Win[i][0] + 0.5F);
  305.          y = (GLint) (VB.Win[i][1] + 0.5F);
  306.          z = (GLint) (VB.Win[i][2] * DEPTH_SCALE);
  307.  
  308.          if (isize&1) {
  309.             /* odd size */
  310.             x0 = x - isize/2;
  311.             x1 = x + isize/2;
  312.             y0 = y - isize/2;
  313.             y1 = y + isize/2;
  314.          }
  315.          else {
  316.             /* even size */
  317.             x0 = (GLint) (x + 0.5F) - isize/2;
  318.             x1 = x0 + isize-1;
  319.             y0 = (GLint) (y + 0.5F) - isize/2;
  320.             y1 = y0 + isize-1;
  321.          }
  322.  
  323.          PB_SET_COLOR( VB.Color[i] );
  324.  
  325.          for (iy=y0;iy<=y1;iy++) {
  326.             for (ix=x0;ix<=x1;ix++) {
  327.                PB_WRITE_PIXEL( ix, iy, z );
  328.             }
  329.          }
  330.          PB_CHECK_FLUSH
  331.       }
  332.    }
  333. }
  334.  
  335.  
  336.  
  337.  
  338. /*
  339.  * Textured RGBA points.
  340.  */
  341. static void textured_rgba_points( GLuint first, GLuint last )
  342. {
  343.    GLuint i;
  344.  
  345.    for (i=first;i<=last;i++) {
  346.       if (VB.Unclipped[i]) {
  347.          GLint x, y, z;
  348.          GLint x0, x1, y0, y1;
  349.          GLint ix, iy;
  350.          GLint isize;
  351.          GLint red, green, blue, alpha;
  352.          GLfloat s, t;
  353.  
  354.          x = (GLint) (VB.Win[i][0] + 0.5F);
  355.          y = (GLint) (VB.Win[i][1] + 0.5F);
  356.          z = (GLint) (VB.Win[i][2] * DEPTH_SCALE);
  357.  
  358.          isize = (GLint)
  359.                    (CLAMP(CC.Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE) + 0.5F);
  360.          if (isize<1) {
  361.             isize = 1;
  362.          }
  363.  
  364.          if (isize&1) {
  365.             /* odd size */
  366.             x0 = x - isize/2;
  367.             x1 = x + isize/2;
  368.             y0 = y - isize/2;
  369.             y1 = y + isize/2;
  370.          }
  371.          else {
  372.             /* even size */
  373.             x0 = (GLint) (x + 0.5F) - isize/2;
  374.             x1 = x0 + isize-1;
  375.             y0 = (GLint) (y + 0.5F) - isize/2;
  376.             y1 = y0 + isize-1;
  377.          }
  378.  
  379.          red   = (GLint) VB.Color[i][0] * CC.RedScale;
  380.          green = (GLint) VB.Color[i][1] * CC.GreenScale;
  381.          blue  = (GLint) VB.Color[i][2] * CC.BlueScale;
  382.          alpha = (GLint) VB.Color[i][3] * CC.AlphaScale;
  383.          s = VB.TexCoord[i][0];
  384.          t = VB.TexCoord[i][1];
  385.  
  386.          PB_SET_COLOR( VB.Color[i] );
  387.  
  388.          for (iy=y0;iy<=y1;iy++) {
  389.             for (ix=x0;ix<=x1;ix++) {
  390.                PB_WRITE_TEX_PIXEL( ix, iy, z, red, green, blue, alpha, s, t );
  391.             }
  392.          }
  393.          PB_CHECK_FLUSH
  394.       }
  395.    }
  396. }
  397.  
  398.  
  399.  
  400.  
  401. /*
  402.  * Examine the current context to determine which point drawing function
  403.  * should be used.
  404.  */
  405. void gl_set_point_function( void )
  406. {
  407.    /* TODO: antialiased points */
  408.  
  409.    if (CC.RenderMode==GL_RENDER) {
  410.       CC.PointsFunc = (*DD.get_points_func)();
  411.       if (CC.PointsFunc) {
  412.          /* Device driver will draw points. */
  413.       }
  414.       else if (CC.Texture.Enabled) {
  415.      CC.PointsFunc = textured_rgba_points;
  416.       }
  417.       else if (CC.Point.Size==1.0) {
  418.          /* size=1, any raster ops */
  419.          CC.PointsFunc = CC.RGBAflag ? size1_rgba_points : size1_ci_points;
  420.       }
  421.       else {
  422.      /* every other kind of point rendering */
  423.      CC.PointsFunc = CC.RGBAflag ? general_rgba_points : general_ci_points;
  424.       }
  425.    }
  426.    else if (CC.RenderMode==GL_FEEDBACK) {
  427.       CC.PointsFunc = feedback_points;
  428.    }
  429.    else {
  430.       /* GL_SELECT mode */
  431.       CC.PointsFunc = select_points;
  432.    }
  433.  
  434. }
  435.  
  436.  
  437.